/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.pay.web.upop;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.pay.entity.upop.EcOrgUpop;
import com.thinkgem.jeesite.modules.pay.service.upop.EcOrgUpopService;

/**
 * 银联Controller
 * @author Egan
 * @version 2016-12-26
 */
@Controller
@RequestMapping(value = "${adminPath}/pay/upop/ecOrgUpop")
public class EcOrgUpopController extends BaseController {

	@Autowired
	private EcOrgUpopService ecOrgUpopService;
	
	@ModelAttribute
	public EcOrgUpop get(@RequestParam(required=false) String id) {
		EcOrgUpop entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = ecOrgUpopService.get(id);
		}
		if (entity == null){
			entity = new EcOrgUpop();
		}
		return entity;
	}
	
	@RequiresPermissions("pay:upop:ecOrgUpop:view")
	@RequestMapping(value = {"list", ""})
	public String list(EcOrgUpop ecOrgUpop, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EcOrgUpop> page = ecOrgUpopService.findPage(new Page<EcOrgUpop>(request, response), ecOrgUpop); 
		model.addAttribute("page", page);
		return "modules/pay/upop/ecOrgUpopList";
	}

	@RequiresPermissions("pay:upop:ecOrgUpop:view")
	@RequestMapping(value = "form")
	public String form(EcOrgUpop ecOrgUpop, Model model) {
		model.addAttribute("ecOrgUpop", ecOrgUpop);
		return "modules/pay/upop/ecOrgUpopForm";
	}

	@RequiresPermissions("pay:upop:ecOrgUpop:edit")
	@RequestMapping(value = "save")
	public String save(EcOrgUpop ecOrgUpop, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, ecOrgUpop)){
			return form(ecOrgUpop, model);
		}
		ecOrgUpopService.insertUPOP(ecOrgUpop);
		addMessage(redirectAttributes, "保存银联成功");
		return "redirect:"+Global.getAdminPath()+"/pay/upop/ecOrgUpop/?repage";
	}
	
	@RequiresPermissions("pay:upop:ecOrgUpop:edit")
	@RequestMapping(value = "delete")
	public String delete(EcOrgUpop ecOrgUpop, RedirectAttributes redirectAttributes) {
		ecOrgUpopService.delete(ecOrgUpop);
		addMessage(redirectAttributes, "删除银联成功");
		return "redirect:"+Global.getAdminPath()+"/pay/upop/ecOrgUpop/?repage";
	}

}